//
//  MemberListCell.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/10.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "MemberListCell.h"

@interface MemberListCell()

@property(nonatomic,strong)UILabel *address;
@property(nonatomic,strong)UILabel *address1;
@property(nonatomic,strong)UILabel *userName;
@property(nonatomic,strong)UILabel *integral;
@property(nonatomic,strong)UILabel *integral1;
@property(nonatomic,strong)UILabel *grade;
@property(nonatomic,strong)UILabel *grade1;
@property(nonatomic,strong)UILabel *createDate;
@property(nonatomic,strong)UILabel *createDate1;
@property(nonatomic,strong)UIImageView*seximage;
@property(nonatomic,strong)UIImageView*headerImage;
@property(nonatomic,strong)UIButton*chooseBtn;
@property(nonatomic,strong)UIButton*chooseBtn1;
@property(nonatomic,strong)UIButton*chooseBtn2;
@property(nonatomic,strong)UIButton*chooseBtn3;
@property(nonatomic,strong)UILabel *lineLabel;
@property(nonatomic,strong)UIImageView*certificationImage;

@end
@implementation MemberListCell
{
    NSMutableArray*memberIdArrays;
    
}
@synthesize mDelegate;
- (void)awakeFromNib {
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        memberIdArrays=[[NSMutableArray alloc]init];
   
    }
    
    return self;
    
}
-(void)createView
{
    self.headerImage=[[UIImageView alloc] init];
    [self.headerImage.layer setCornerRadius:4.0];
    [self.headerImage.layer setBorderWidth:0.10];
    [self.headerImage.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0.93, 0.93, 0.93, 0.93 });
    [self.headerImage.layer setBorderColor:colorref2];
    [self addSubview:self.headerImage];
    
    
    self.userName=[[UILabel alloc] init];
    self.userName.font= [UIFont systemFontOfSize:16];
    self.userName.textColor=[UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0];
    [self addSubview:self.userName];
    self.seximage=[[UIImageView alloc] init];
    [self addSubview:self.seximage];
    self.integral=[[UILabel alloc] init];
    self.integral.font= [UIFont systemFontOfSize:14];
    self.integral.text=@"积分";
    self.integral.textColor=zhonghuiColor;
    [self addSubview:self.integral];
    self.integral1=[[UILabel alloc] init];
    self.integral1.font= [UIFont systemFontOfSize:14];
    self.integral1.textColor=shenhuiColor;
    [self addSubview:self.integral1];
    self.grade=[[UILabel alloc] init];
    self.grade.font= [UIFont systemFontOfSize:14];
    self.grade.text=@"";
    self.grade.textColor=zhonghuiColor;
    [self addSubview:self.grade];
    self.grade1=[[UILabel alloc] init];
    self.grade1.font= [UIFont systemFontOfSize:13.5];
    [self.grade1.layer setCornerRadius:1.5];
    [self.grade1.layer setBorderWidth:0];
    self.grade1.textAlignment=NSTextAlignmentCenter;
    [self.grade1.layer setMasksToBounds:YES];
    self.grade1.textColor=[UIColor whiteColor];
    [self addSubview:self.grade1];
    
    
    self.chooseBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-40, 45-25/2, 30, 30)];
    [self.chooseBtn setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [self addSubview:self.chooseBtn];

    self.chooseBtn1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-80, 0, 80, 90)];
    [self.chooseBtn1 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
    [self addSubview:self.chooseBtn1];
    
    self.certificationImage=[[UIImageView alloc] init];
    [self addSubview:self.certificationImage];

    
    self.lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(10, 90, ScreenWidth-20, 0.45)];
    [self.lineLabel setBackgroundColor:[UIColor colorWithRed:238.0f/255.0f green:238.0f/255.0f blue:238.0f/255.0f alpha:1.0f]];
    self.lineLabel.textColor=[UIColor clearColor];
    [self addSubview:self.lineLabel];

   
    
}
-(void)setModel:(MemberListModel *)model
{
    [self createView];
    [self setViewAutoLayout];
    NSMutableArray *buttonContent = [model.tags copy];
    for (int i = 0;  i<buttonContent.count; i++) {
        if (i>2) {
            }else{
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(75+60*(i+1)-60,50, 55, 16);
            [button setTitle:[[buttonContent objectAtIndex:i]objectForKey:@"content"] forState:UIControlStateNormal];
            button.titleLabel.font=[UIFont systemFontOfSize:10];
            CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
            CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){209/255.0,170/255.0, 56/255.0, 1.0   });
            button.backgroundColor=[UIColor colorWithRed:255/255.0 green:255/255.0 blue:234/255.0 alpha:1];
            [button.layer setBorderColor:colorref2];//边框颜色
            [button.layer setBorderWidth:0.5];
            [button.layer setCornerRadius:7.5];
            button.userInteractionEnabled=NO;
            [button setTitleColor:[UIColor colorWithRed:209/255.0 green:170/255.0 blue:56/255.0 alpha:1.0] forState:0];
            button.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
            [self addSubview:button];
        }
        
        
    }
    [self.headerImage setImageWithURL:[NSURL URLWithString:model.headImage]placeholderImage:[UIImage imageNamed:@"touxiang"]];
    self.integral1.text=[NSString stringWithFormat:@"%@",  model.integral];
    self.userName.text=[NSString stringWithFormat:@"%@",  model.userName];
    self.lineLabel.text=[NSString stringWithFormat:@"%@",model.integral];
  
    
         
        
    if (model.sex==NULL|| [[Global getJudgeTheErrorStr:model.sex]isEqualToString:@""]){
        
        if ([model.sex isEqualToString:@"男"]) {
            self.seximage.image=[UIImage imageNamed:@"nan"];
        }else{
            self.seximage.image=[UIImage imageNamed:@"nv"];
        }
    }else{
        self.seximage.image=[UIImage imageNamed:@"nv"];}
//    if ([[NSString stringWithFormat:@"%@", model.gradeName ] isEqualToString:@"金"]) {
        self.grade1.text=model.gradeName;
        self.grade1.backgroundColor=[UIColor colorWithRed:209/255.0 green:170/255.0 blue:56/255.0 alpha:1.0];
//    }
    if ([[NSString stringWithFormat:@"%@", model.gradeName] isEqualToString:@"银"]) {
        self.grade1.text=@"银";
        self.grade1.backgroundColor=[UIColor colorWithRed:175/255.0 green:175/255.0 blue:175/255.0 alpha:1.0];
    }
    if ([[NSString stringWithFormat:@"%@", model.gradeName] isEqualToString:@"铜"]) {
        self.grade1.text=@"铜";
        self.grade1.backgroundColor=[UIColor colorWithRed:126/255.0 green:56/255.0 blue:39/255.0 alpha:1.0];
    }
   
    if ([self.chooseState isEqualToString:@"选择"]) {
        self.chooseBtn.userInteractionEnabled=NO;
        self.chooseBtn1.userInteractionEnabled=NO;
   
    }else{
        
        [self.chooseBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
        [self.chooseBtn setTitle:model.memberId forState:UIControlStateNormal];
        [self.chooseBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self.chooseBtn1 addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self.chooseBtn1 setTitle:model.memberId forState:UIControlStateNormal];
        self.saveAccount=NO;
        if ([self.memberIdArray containsObject:model.memberId]) {
            self.saveAccount=YES;
            [self.chooseBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
            [self.chooseBtn setTitle:model.memberId forState:UIControlStateNormal];
            [self.chooseBtn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
        }
        
         self.certificationImage.image=[UIImage imageNamed:@"yirenzheng"];
    }
    
 

if (model.phone==NULL||  [[Global getJudgeTheErrorStr:model.phone]isEqualToString:@""]){
        self.certificationImage.image=[UIImage imageNamed:@""];
        self.chooseBtn.userInteractionEnabled=NO;
        [self.chooseBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        self.chooseBtn1.userInteractionEnabled=NO;
       
        self.chooseBtn2=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-80, 0, 55, 25)];
        [self.chooseBtn2 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
        self.chooseBtn2.center= self.chooseBtn1.center;
        [self.chooseBtn2 setTitle:@"去认证" forState:UIControlStateNormal];
        self.chooseBtn2. titleLabel.font=[UIFont systemFontOfSize:13];
        [self.chooseBtn2 setTitleColor:luseColor forState:UIControlStateNormal];
        self.chooseBtn2.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
        [self.chooseBtn2.layer setCornerRadius:2.0]; //设置矩圆角半径
        [self.chooseBtn2.layer setBorderWidth:0.40];   //边框宽度
        CGColorSpaceRef tureBTnSpace = CGColorSpaceCreateDeviceRGB();
        CGColorRef tureBTncolorref = CGColorCreate(tureBTnSpace,(CGFloat[]){90/255.0, 130/255.0, 26/255.0, 1.0});
        [self.chooseBtn2.layer setBorderColor:tureBTncolorref];//边框颜色

        [self addSubview:self.chooseBtn2];
       
        self.chooseBtn3=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-80, 0, 70, 90)];
        [self.chooseBtn3 setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
        self.chooseBtn3.center= self.chooseBtn1.center;
        [self.chooseBtn3 setTitle: self.tagStr forState:UIControlStateNormal];
        [self.chooseBtn3 addTarget:self action:@selector(goBtn:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.chooseBtn3];

    
      
        
}
    
}
-(void)goBtn:(UIButton*)sender{

    [mDelegate certification:sender.titleLabel.text];

}

-(void)chooseBtn:(UIButton*)sender{
        NSLog(@"%@",sender.titleLabel.text);
    self.saveAccount=! self.saveAccount;
    if (!self.saveAccount) {
        [mDelegate chooseBtn:sender.titleLabel.text];
        [self.chooseBtn setImage:[UIImage imageNamed:@"quans"] forState:UIControlStateNormal];
}
    else{

        [mDelegate chooseBtn:sender.titleLabel.text];
        [self.chooseBtn setImage:[UIImage imageNamed:@"gous"] forState:UIControlStateNormal];
    }
}
-(void)setViewAutoLayout
{
    
    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(15) ;
        make.height.equalTo(@50);
        make.width.equalTo(@50);
        make.top.equalTo(self.mas_top).with.offset(20);
    }];
    [self.certificationImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(14) ;
        make.height.equalTo(@15);
        make.width.equalTo(@15);
        make.top.equalTo(self.mas_top).with.offset(20+36);
    }];
    
    [self.userName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerImage.mas_right).with.offset(10);
        make.height.equalTo(@16);
        make.top.equalTo(self.mas_top).with.offset(25);
    }];
    
    [self.seximage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userName.mas_right).with.offset(3);
        make.width.equalTo(@20);
        
        make.height.equalTo(@20);
        
     make.centerY.equalTo(self.userName.mas_centerY) ;
    }];
    [self.grade mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.seximage.mas_right).with.offset(5);
        
        make.height.equalTo(@14);
        
        make.centerY.equalTo(self.seximage.mas_centerY) ;
    }];
    
    [self.grade1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.grade.mas_right).with.offset(5);
        make.height.equalTo(@14);
//        make.width.equalTo(@14);
        make.centerY.equalTo(self.seximage.mas_centerY) ;
        
    }];
    [self.integral mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.grade1.mas_right).with.offset(10);
        
        make.height.equalTo(@14);
        
        make.centerY.equalTo(self.seximage.mas_centerY) ;
    }];
    
    [self.integral1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.integral.mas_right).with.offset(3);
        make.height.equalTo(@14);
        
        make.centerY.equalTo(self.seximage.mas_centerY) ;
        
    }];
    
    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-10) ;
        
        make.height.equalTo(@0.5);
        
        make.top.equalTo(self.mas_top).with.offset(89.5);

    }];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
